package com.kitty.htmlparser;

import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.Tag;
import org.htmlparser.filters.TagNameFilter;
import org.htmlparser.tags.LinkTag;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;
import org.htmlparser.visitors.HtmlPage;
import org.htmlparser.visitors.NodeVisitor;


public class HtmlParserMain {

	/**
	 * @param args
	 * @throws ParserException 
	 */
	public static void main(String[] args) throws ParserException {
		
		 
		Parser parser = new Parser();

		 parser.setURL("http://www.baidu.com"); parser.setEncoding(parser.getEncoding());

		 NodeVisitor visitor =  new NodeVisitor() {
			 public void visitTag(Tag tag) {
				 System.out.print("tag name is:"+tag.getTagName()+"\n class is:"+tag.getClass());
			 }
		 };
		 parser.visitAllNodesWith(visitor);
		
		/*
		String htmlcode = "<HTML><HEAD><TITLE>AAA</TITLE></HEAD><BODY>" + "content" + "</BODY></HTML>";
		Parser parser = Parser.createParser(htmlcode, "GBK");
		HtmlPage page = new HtmlPage(parser);
		try
		 { parser.visitAllNodesWith(page);}
		 catch (ParserException e1)
		 { e1 = null;}
		 NodeList nodelist = page.getBody();
		 NodeFilter filter = new TagNameFilter("A");
		 nodelist = nodelist.extractAllNodesThatMatch(filter, true);
		 for (int i = 0; i < nodelist.size(); i++)
		 {
			 LinkTag link=(LinkTag) nodelist.elementAt(i);
		 }
		 */			  
		 

	 
		
		
		
		
		
		
		
		
		
		
		
		
		
	}
	}

